/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public int[] levelOrder(TreeNode root) {
        if(null == root) {
            return new int[] {};
        }
        Queue<TreeNode> quene = new LinkedList<>();
        ArrayList<Integer> tmp = new ArrayList<>();
        TreeNode cur = root;
        quene.offer(root);
        while(!quene.isEmpty()) {
            cur = quene.poll();
            tmp.add(cur.val);
            if(null != cur.left) {
                quene.offer(cur.left);
            }
            if(null!= cur.right) {
                quene.offer(cur.right);
            }
        }
        int[] arr = new int[tmp.size()]; 
        for(int i = 0;i<tmp.size();i++) {
            arr[i] = tmp.get(i);
        }
        return arr;
    }
}